/**
 * 
 */
package fr.gfi.agraf.persistence.dao.impl;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.NoResultException;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import fr.gfi.agraf.persistence.dao.INotificationDAO;
import fr.gfi.agraf.persistence.entity.Notification;
import fr.gfi.agraf.utils.PropertiesUtils;

/**
 * @author Zakaria
 * 
 */
@Repository
public class NotificationDAO extends AbstractGenericDAO<Notification> implements INotificationDAO {

	private static final String HQL_NOTIFICATION_BY_USER_NON_LUE = "hql.notification.selectByUtilisateurNonLues";
	private static final String HQL_NOTIFICATION_BY_USER_LIMITED = "hql.notification.selectByUtilisateurLimited";

	/**
	 * Logger
	 */
	private final static Logger LOGGER = Logger.getLogger(ComposantDAO.class);

	public List<Notification> getNotificationsByUserNonLues(final Long idUser) {
		List<Notification> output = null;
		final String query = PropertiesUtils.getProperty(HQL_NOTIFICATION_BY_USER_NON_LUE);
		try {
			output = em.createQuery(query, Notification.class).setParameter("idUtilisateur", idUser)
					.getResultList();
		} catch (final NoResultException e) {
			output = new ArrayList<Notification>();
			LOGGER.debug(e);
		}
		return output;
	}

	public List<Notification> getAllNotificationsByUserLimited(final Long idUser, final int limite) {
		List<Notification> output = null;
		final String query = PropertiesUtils.getProperty(HQL_NOTIFICATION_BY_USER_LIMITED);
		try {
			output = em.createQuery(query, Notification.class).setParameter("idUtilisateur", idUser)
					.setMaxResults(limite).getResultList();
		} catch (final NoResultException e) {
			output = new ArrayList<Notification>();
			LOGGER.debug(e);
		}
		return output;
	}

}
